Imports System.Collections.Generic

Public Class NameValue
  Sub New()
  End Sub
  Public Sub New(ByVal n As String, ByVal v As Integer)
    Name = n
    Value = v
  End Sub
  Private _name As String
  Public Property Name() As String
    Get
      Return _name
    End Get
    Set(ByVal value As String)
      _name = value
    End Set
  End Property

  Private _value As Integer
  Public Property Value() As Integer
    Get
      Return _value
    End Get
    Set(ByVal value As Integer)
      _value = value
    End Set
  End Property

End Class

Public Class NameValueList
  Inherits List(Of NameValue)

  Sub New()
  End Sub
  Sub New(ByVal csvString As String, ByVal withValues As Boolean)
    Dim arNV As String() = csvString.Split(","c)
    If withValues Then
      For index As Integer = 0 To arNV.Length - 2 Step 2
        Dim nv As New NameValue(arNV(index), CInt(arNV(index + 1)))
        Me.Add(nv)
      Next
    Else
      For index As Integer = 0 To arNV.Length - 1
        Dim nv As New NameValue(arNV(index), index)
        Me.Add(nv)
      Next
    End If
  End Sub
  Public Sub SetDataSourceOf(ByVal lc As ListControl)
    lc.ValueMember = "Value"
    lc.DisplayMember = "Name"
    lc.DataSource = Me
    If TypeOf lc Is ComboBox Then
      CType(lc, ComboBox).MaxDropDownItems = Me.Count
    End If
  End Sub
End Class
